Hello all,

I have recently started to implement the SHA-256 checksum algorithm in C as an education exercise. I was moving along quite well until I reached the point where I needed to perform addition modulo 2^32 on a number of 32-bit words.

Basically, I am storing these 32-bit chunks and I need to perform this addition modulo 2^32 as stated in the specification.

The code:
Code:
#define BOUND 0x100000000    /* 2^32 */

unsigned int schedule[blocks][64];

...
unsigned int temp = (F4(schedule[i][j-2]) + schedule[i][j-7]) % BOUND;
temp = (temp + ((F3(schedule[i][j-15]) + schedule[i][j-16]) % BOUND)) % BOUND;

schedule[i][j] = temp;
The compiler prints the following warning for the code using the modulus operator:

sha_256.c:246: warning: integer constant is too large for ‘long’ type

F3 and F4 are functions defined by the specification which rotate and shift the bits of a 32-bit word. I know I am supposed to be storing this into 32-bits, but if I mod 2^32 apparently this won't work.

Can someone help me see what I am not understanding with the specification and/or my code? I suppose theoretically I could be summing (2^32-1) or a similarly large number, but that would just cause problems when i store the value. I am not sure exactly why this is a problem.

Thanks for looking!

(hopefully I explained everything enough, if not, let me know as I am sure you will)